<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>系统管理</title>
</head>
<body>
<div class="box">
    <!-- /.box-header -->
    <section class="content">
        <div class="box-body">
            <form role="form">
                <div class="form-group col-md-7">
                    <label>目录等级</label>
                    <select id="level" class="form-control">
                        <option value="">请选择...</option>
                        <option {if condition='$modulea.level eq 1'}selected="selected"{else/} {/if} value="1">一级目录</option>
                        <option {if condition='$modulea.level eq 2'}selected="selected"{else/} {/if} value="2">二级目录</option>
                    </select>
                </div>
                <div class="form-group col-md-7">
                    <label>上级目录</label>
                    <select id="pid" class="form-control" disabled>
                        <option value="0">请选择...</option>
                        {volist name='list' id='v'}
                        <option {if condition="$v.id eq $modulea.pid"} selected="selected" {/if} value="{$v.id}">{$v.title}</option>
                        {/volist}
                    </select>
                </div>
                <div class="form-group col-md-7" >
                    <label>模块名称</label>
                    <input type="text" id="title" class="form-control" value="{$modulea.title}" placeholder="例：系统管理">
                </div>
                <div class="form-group col-md-7" >
                    <label>所在模块</label>
                    <input type="text" id="moduleaname" class="form-control" value="{$modulea.modulea}" placeholder="例：system">
                </div>
                <div class="form-group col-md-7" >
                    <label>路径</label>
                    <input type="text" id="route" class="form-control" value="{$modulea.route}" placeholder="例：system/addModulea">
                </div>
                <div class="form-group col-md-7" >
                    <label>排序（数字越大排序越低）</label>
                    <input type="text" id="sort" class="form-control" value="{$modulea.sort}" placeholder="例：1 " >
                </div>
                <div class="form-group col-md-7" >
                    <label>图标</label>
                    <input type="text" id="icon" class="form-control" value="{$modulea.icon}" placeholder="例：fa-share">
                </div>
                <input type="hidden" id="mid" value="{$modulea.id}">
                <div class="form-group col-md-7">
                    <div id="btn_edit" class="btn btn-info btn-flat pull-right">保存修改</div>
                </div>
            </form>
        </div>
        <!-- /.box-body -->
    </section>
</div>
</body>
<script>
    function reselect(){
        var _val = $('#level').val();
        if(_val == 2){
            $('#pid').removeAttr('disabled');
        }else{
            $('#pid').attr('disabled','disabled');
            $('#pid').val('0');
        }
    }
    $(function(){
        reselect();
        $('#level').click(function(){
            var _val = $(this).val();
            if(_val == 2){
                $('#pid').removeAttr('disabled');
            }else{
                $('#pid').attr('disabled','disabled');
                $('#pid').val('0');
            }
        })
        $('#btn_edit').click(function(){
            var _mid = $('#mid').val();
            var _level = $('#level').val();
            var _title = $('#title').val();
            var _pid = $('#pid').val();
            var _modulea = $('#moduleaname').val();
            var _route = $('#route').val();
            var _icon = $('#icon').val();
            var _sort = $('#sort').val();
            if(_level == ''){
                layerAlert('请选择目录等级');
                return false;
            }
            if(_level == 2 && _pid == 0){
                layerAlert('请选择上级目录');
                return false;
            }
            if(_title == ""){
                layerAlert('请输入模块名称');
                return false;
            }
            if(_modulea == ""){
                layerAlert('请输入所在模块');
                return false;
            }
            if(_level == 2 &&_route == ""){
                layerAlert('请输入路径');
                return false;
            }
            $.ajax({
                cache: false,
                url:"{:url('system/doEditModulea')}",
                data:{id:_mid,level:_level,title:_title,pid:_pid,route:_route,icon:_icon,modulea:_modulea,sort:_sort},
                type:'post',
                success:function(data){
                    if(data.code == 0){
                        layerAlert('修改成功',function(){
                            parent.parent.window.location.reload();
                        });
                    }else {
                        layerAlert('修改失败');
                    }

                },
                error:function(){
                    layerAlert('系统错误，请联系管理员');
                }
            })
        })
    })
</script>
</html>